import { BLOCK_GS_COLOR, S_CELL_GS_WIDTH } from "./GameGSDefine";

cc.Class({
    extends: cc.Component,

    properties: {
        nodParticle: [cc.Node],
    },

    init(color, x, y) {
        let index;
        if (color === BLOCK_GS_COLOR.BLUE) {
            index = 0;
        } else if (color === BLOCK_GS_COLOR.GREEN) {
            index = 1;
        } else if (color === BLOCK_GS_COLOR.PURPLE) {
            index = 2;
        } else if (color === BLOCK_GS_COLOR.RED) {
            index = 3;
        } else if (color === BLOCK_GS_COLOR.YELLOW) {
            index = 4;
        }

        for (let i = 0; i < 5; i++) {
            if (i == index) {
                this.nodParticle[i].active = true;
            } else {
                this.nodParticle[i].active = false;
            }
        }

        this.nodParticle[index].getComponent(cc.ParticleSystem).resetSystem();

        this.updatePosition(x, y);

        this.scheduleOnce(() => {
            F.Utils.putPoolFuckNode('nodePoolParticle',this.node);
        }, 3);
    },

    // 更新位置
    updatePosition(x, y) {
        let cellX = x * S_CELL_GS_WIDTH - 4.5 * S_CELL_GS_WIDTH;
        let cellY = y * S_CELL_GS_WIDTH - 4.5 * S_CELL_GS_WIDTH;
        this.node.x = cellX;
        this.node.y = cellY;
        
    },
});
